#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>


int main(int argc, char *argv[])
{
    struct gameState *state = newGame();
    int *bonus = malloc(sizeof(int));
    int i, j, handSize, deckSize, discardSize;
    srand(time(NULL));
    //initialize state
    state->numPlayers = 2;
    state->whoseTurn = 0;

    for(i=0; i<100; i++){
        state->numActions = 1;
        deckSize = (rand() % 100);
        handSize = (rand() % 100)+1;
        discardSize = (rand() % 100);
        state->deckCount[0] = deckSize;
        state->handCount[0] = handSize;
        state->discardCount[0] = discardSize;
        state->hand[0][0] = adventurer;//Make sure that adventure can be played.
        //Fill deck, hand, and discard with random cards.
        for (j=0; j<deckSize; j++){
            state->deck[0][j] = (rand() % 27);
        }
        for (j=1; j<handSize; j++){
            state->hand[0][j] = (rand() % 27);
        }
        for (j=0; j<discardSize; j++){
            state->discard[0][j] = (rand() % 27);
        }
        /*printf("\nOriginal hand:\n");
        for (j=0; j<handSize; j++){
             printf("%d ", state->hand[0][j]);
        }
        printf("\nModified hand:\n");
        for (j=0; j<state->handCount[0]; j++){
             printf("%d ", state->hand[0][j]);
        }*/
        cardEffect(adventurer,0,0,0,state,0,bonus);//run the card
        //check if the last two cards in the hand are treasure
        if(copper<=state->hand[0][state->handCount[0]-2] && state->hand[0][state->handCount[0]-2]<=gold &&
                copper<=state->hand[0][state->handCount[0]-1] && state->hand[0][state->handCount[0]-1]<=gold )
            printf("PASSED, the two top cards in the hand are treasure\n");
        else
            printf("FAILED, the top two cards in the hand are not treasures\n");
        //check if hand size is correct. Should be 1 greater than given handSize becuase of gaining two cards and losing adventurer
        if (state->handCount[0] == handSize+1)
            printf("PASSED, hand size grew by one\n");
        else
            printf("FAILEd, hand size is %d when the original hand size was %d\n", state->handCount[0], handSize);
    }
}
